<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>AUI快速完成布局</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
</head>
<body>
    <section class="aui-content">
      <div class="aui-card-list">
          <div class="aui-card-list-content">
              <ul class="aui-list aui-media-list" id="users-list">

              </ul>
          </div>
      </div>
    </section>
</body>
<script type="text/javascript" src="../script/zepto.min.js" ></script>
<script type="text/javascript" src="../script/api.js" ></script>
<script type="text/javascript" src="../script/aui-toast.js" ></script>
<script type="text/javascript">
var toast = new auiToast();
apiready = function(){
     $api.setStorage("mail_index", 0);
     load();
     //上拉翻页
     api.addEventListener({
         name : 'scrolltobottom'
     }, function(ret, err) {
         $api.setStorage("mail_index", $api.getStorage("mail_index") - 0 + 1);
         load();
     });
 }

//资讯列表加载
 function load(first, index2) {
     api.showProgress({
        style: 'default',
        animationType: 'fade',
        title: '拼命加载中...',
        text: '不如喝茶去...',
        modal: false
     });
     var index = $api.getStorage("mail_index");
     var url = ServeUrl + "m=Daily&a=userInfo&pageIndex=" + index + "&pageCount=15";
     ajaxRequest(url, 'get', '', function(data) {
         dealWithHtml(data, first, index);
     });

 }

 function ajaxRequest(url, method, datas, callBack) {
     api.ajax({
         url : url,
         method : method,
         cache : false,
         timeout : 30,
         dataType : 'json',
         data : {
             values : datas
         }
     }, function(ret, err) {
         if (ret.data) {
             callBack(ret, err);
         } else {
             //alert("没有更多的用户！");
             toast.success({
                 title:"已加载所有用户",
                 duration:2000
             });
             api.hideProgress();
         }
     });
 }

//字符串拼接
 function dealWithHtml(data, first, index) {
    //alert(JSON.stringify(data));
     var html = '';
     for (var i = 0; i < data.data.length; i++) {
        html+='<li class="aui-list-item aui-list-item-middle" onclick="openWin('+"'"+data.data[i].username+"','"+data.data[i].cn_name+"',"+"'"+data.data[i].r_name+"',"+"'"+data.data[i].d_name+"',"+"'"+data.data[i].phone+"'"+');">'
        html+='<div class="aui-media-list-item-inner">'
        html+='<div class="aui-list-item-media" style="width: 3rem;">'
        html+='<img src="../image/demo5.png" class="aui-img-round" >'
        html+='</div>'
        html+='<div class="aui-list-item-inner aui-list-item-arrow">'
        html+='<div class="aui-list-item-text">'
        html+='<div class="aui-list-item-title aui-font-size-14">'+data.data[i].username+'/'+data.data[i].cn_name+'</div>'
        html+='<div class="aui-list-item-right">'+data.data[i].r_name+'</div>'
        html+='</div>'
        html+='</div>'
        html+='</div>'
        html+='</li>';
     }
    $("#users-list").append(html);
    api.hideProgress();
     /*if (first == '1') {

         document.getElementById('users-list').innerHTML = html;
         api.hideProgress();
     } else {
         document.getElementById('users-list').innerHTML += html;
         api.hideProgress();
     }*/
 }

    function openWin(username,cn_name,r_name,d_name,phone) {

      //  alert(cn_name);
        api.openWin({
            name: "personal_info",
            url: 'personal_info_win.html',
            pageParam: {
                username: username,
                cn_name: cn_name,
                r_name: r_name,
                d_name: d_name,
                phone: phone,
            }
        });
    }
</script>
</html>
